<!--
    @author Yancy Zhang
    @date 2022/4/6
    @description 博客搜索界面
-->
<template>
  <div class="search-page">
    <div>
      <Header></Header>
    </div>
    <div class="main">
      <div class="auto-play">
        <div>
          <p class="tip"><i class="el-icon-chat-line-square"></i>共有 <span style="color: #42b983">{{blogList.length}}</span> 条结果!</p>
        </div>
        <el-skeleton style="width: 100%;background-color: white" animated :loading="loading">
          <template slot="template">
            <div style="display: flex; padding: 10px">
              <el-skeleton-item variant="image" style="width: 240px; height: 240px;" />
              <el-skeleton style="flex:1;padding: 10px"/>
            </div>
          </template>
          <template slot="template">
            <div style="display: flex; padding: 10px">
              <el-skeleton-item variant="image" style="width: 240px; height: 240px;" />
              <el-skeleton style="flex:1;padding: 10px"/>
            </div>
          </template>
          <template>
            <div class="article-list">
              <router-link :to='"/article-dtail/"+item._id' v-for="item in blogList" :key="item._id">
                <div class="main-article article">
            <span class="article-img-wrap">
              <img :src="item.blog_cover_img" alt="" class="article-img">
              <i></i>
            </span>
                  <div class="article-content">
                    <div>
                      <span class="article-title">{{ item.blog_title }}</span>
                      <span></span>
                    </div>
                    <p class="article-desc">
                      {{ item.blog_desc }}
                    </p>
                    <div class="article-bottom">
                      <span>发布于 {{ item.blog_post_time | formatTime}}</span>
                      <span class="tag">分类：{{ item.blog_type }}</span>
                    </div>
                  </div>
                </div>
              </router-link>
            </div>
          </template>
        </el-skeleton>
      </div>
    </div>
    <div>
      <Footer></Footer>
    </div>
  </div>
</template>

<script>
import Header from "../../components/Header";
import Footer from "../../components/Footer";
import {searchBlog} from "../../http/api";
export default {
  name: "SearchPage",
  components: {
    Header,
    Footer,
  },
  data(){
    return {
      loading: true,
      blogList: []
    }
  },
  created() {
    /*根据搜索的参数去查询数据库*/
    this.search(this.$route.params.keyWord);
  },
  methods:{
    search(keyWord){
      searchBlog(keyWord).then(res=>{
        this.blogList = res;
        this.loading = false;
      })
    }
  },
  watch:{
    $route:function(newVal,oldVal){
      this.search(this.$route.params.keyWord);
    }
  }
}
</script>

<style scoped>
.tip{
  padding: 5px;
}
.main-article{
  display: flex;
  flex-direction: row;
  background-color: white;
  margin-bottom: 20px;
}
.main-article .article-img{
  height: 150px;
  width: 300px;
  max-width: 480px;
}
.article-list{
  padding-top: 50px;
}
/*文字部分*/
.article-title{
  position: relative;
  color: #42b983;
  text-transform: capitalize;
  line-height: 36px;
  display: inline-block;
  border: 0;
  padding: 0;
  font-size: 1.365rem;
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 100%;
  font-weight: 600;
}
.article-content{
  display: flex;
  flex-direction: column;
  padding: 20px;
  flex: 1;
}
.article-desc{
  color: #555;
  flex: 1;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  word-wrap: break-word;
  word-break: break-word;
  text-overflow: ellipsis;
  overflow: hidden;
  -webkit-line-clamp: 2;
}
.article-bottom{
  color: #8d91a5;
}
.article-bottom .tag{
  float: right;
}
/*移动端适配*/
@media screen and (max-width: 1000px){
  .main-article{
    flex-direction: column;
  }
  .main-article .article-img{
    height: 230px;
    width: 100%;
  }
  .second-main-articles{
    flex-direction: column;
  }
  .second-main-articles .second-article{
    width: 100%;
    margin-bottom: 10px;
  }
}
</style>
